<template>
  <div class="registerDetail">
    <!-- 单车详情 -->
    <van-nav-bar
      :fixed="true"
      :placeholder="true"
      :title="$route.meta.title"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <!-- 表单 -->
    <div class="formData">
      <van-field
        readonly
        v-model="dataSource.billNum"
        name="工单编号"
        label="工单编号"
        input-align="right"
      />

      <van-field
        readonly
        v-model="dataSource.fixCenterName"
        name="所属维修中心"
        label="所属维修中心"
        input-align="right"
      />

      <van-field
        v-model="dataSource.empName"
        name="所属服务顾问"
        label="所属服务顾问"
        input-align="right"
        readonly
      />

      <van-field
        v-model="dataSource.workBillType"
        name="工单类型"
        label="工单类型"
        input-align="right"
        readonly
      />

      <van-field
        v-model="dataSource.subType"
        name="工单分类"
        label="工单分类"
        input-align="right"
        readonly
      />

      <van-field
        v-model="dataSource.customerName"
        name="客户名称"
        label="客户名称"
        input-align="right"
        readonly
      />
      <van-field
        v-model="dataSource.carNo"
        name="车牌号码"
        label="车牌号码"
        input-align="right"
        readonly
      />
    </div>
    <!-- 底部tab -->
    <div class="tabBarBox">
      <van-tabs v-model="tabActive">
        <van-tab title="基本信息">
          <div class="tabCar">
            <van-field
              v-model="dataSource.vinCode"
              name="车架号"
              label="车架号"
              input-align="right"
              readonly
            ></van-field>
            <van-field
              v-model="dataSource.carMile"
              name="车辆公里数"
              label="车辆公里数"
              input-align="right"
              readonly
            >
              <template slot="button">km</template>
            </van-field>
            <van-field
              v-model="dataSource.dateIn"
              name="实际进场时间"
              label="实际进场时间"
              input-align="right"
              readonly
            />
            <van-field
              v-model="dataSource.dateIn"
              name="实际完工时间"
              label="实际完工时间"
              input-align="right"
              readonly
            />
            <van-field
              v-model="dataSource.advRepairItem"
              name="建议维修项目"
              label="建议维修项目"
              input-align="right"
              readonly
            />
            <van-field
              label-width="150px"
              v-model="dataSource.advMaintenanceMiles"
              name="建议下次保养里程"
              label="建议下次保养里程"
              input-align="right"
              readonly
            >
              <template slot="button">km</template>
            </van-field>
            <van-field
              label-width="150px"
              v-model="dataSource.advMaintenanceTime"
              name="建议下次保养时间"
              label="建议下次保养时间"
              input-align="right"
              readonly
            />
            <van-field
              v-model="dataSource.repairCus"
              name="送修人"
              label="送修人"
              input-align="right"
              readonly
            />
            <van-field
              v-model="dataSource.repairCusphone"
              name="送修人电话"
              label="送修人电话"
              input-align="right"
              readonly
            />
            <van-field
              v-model="dataSource.totalAmount"
              name="合计金额"
              label="合计金额"
              input-align="right"
              readonly
            />
            <van-field
              v-model="dataSource.receivableAmount"
              name="应收款金额"
              label="应收款金额"
              input-align="right"
              readonly
            />
            <van-field
              v-model="dataSource.noPayments"
              name="已收款金额"
              label="已收款金额"
              input-align="right"
              readonly
            />
          </div>
        </van-tab>
        <van-tab title="人工操作">
          <div
            class="doList"
            v-if="dataSource.kdtEntry && dataSource.kdtEntry.length != 0"
          >
            <div
              class="doList_item"
              v-for="(item, index) in dataSource.kdtEntry"
              :key="index"
            >
              <div class="item_time">工时代码：{{ item.repairItemNum }}</div>
              <div class="item_do">人工操作：{{ item.repairItemName }}</div>
              <div class="item_box flex">
                <div class="item_txt">标准工时：{{ item.standardTime }}</div>
                <div class="item_txt">单价：{{ item.price }}</div>
                <div class="item_txt">金额：{{ item.amount }}</div>
              </div>
            </div>
          </div>
          <van-empty class="noContent" description="暂无数据" v-else />
        </van-tab>
        <van-tab title="配件信息">
          <div
            class="doList"
            v-if="dataSource.kdtMaterial && dataSource.kdtMaterial.length != 0"
          >
            <div
              class="doList_item"
              v-for="(item, index) in dataSource.kdtMaterial"
              :key="index"
            >
              <div class="item_do">
                <div class="item_name">配件编号：</div>
                <div>{{ item.materialNum }}</div>
              </div>
              <div class="item_do">
                <div class="item_name">配件名称：</div>
                <div>{{ item.materialName }}</div>
              </div>
              <div class="item_box flex">
                <div class="item_txt">数量：{{ item.qty }}</div>
                <div class="item_txt">单价：{{ item.price }}</div>
                <div class="item_txt">金额：{{ item.amount }}</div>
              </div>
            </div>
          </div>
          <van-empty class="noContent" description="暂无数据" v-else />
        </van-tab>
        <van-tab title="卡券抵用信息">
          <div
            class="cardList"
            v-if="dataSource.kdtVoucher && dataSource.kdtVoucher.length != 0"
          >
            <div
              class="cardItem"
              v-for="(item, index) in dataSource.kdtVoucher"
              :key="index"
            >
              <div class="box flex">
                <div class="cardItem_lt flex">
                  <div class="price_icon">¥</div>
                  <div class="price">
                    <div class="txt">{{ item.amount }}</div>
                    <div class="name">{{ item.couponsType }}</div>
                  </div>
                </div>
                <div class="cardItem_rt">
                  <div class="label_name flex">
                    <div class="label_txt1">
                      {{ item.voucherName }}
                    </div>
                  </div>
                  <div class="label_time">{{ item.deDate }}已使用</div>
                </div>
              </div>
              <div class="cardNo">券号{{ item.voucherNum }}</div>
            </div>
          </div>
          <van-empty class="noContent" description="暂无数据" v-else />
        </van-tab>
      </van-tabs>
      <!-- <div
        class="submitBtn"
        @click="handleApply"
      >申请结算</div> -->
    </div>
  </div>
</template>

<script>
import {
  Search,
  Empty,
  Field,
  Form,
  Uploader,
  DatetimePicker,
  Notify,
  Dialog,
} from 'vant'
import repairApi from '@/api/repairApi'
import { getCookies } from '../../utils/util'
import commonApi from '@/api/commonApi'
export default {
  name: 'repairOrderDetail',
  components: {
    Search,
    Empty,
    Field,
    Form,
    Uploader,
    DatetimePicker,
    [Dialog.Component.name]: Dialog.Component,
  },
  data() {
    return {
      showTimerPicker: false,
      dataSource: {
        billId: '', //单据ID
        vinCode: '', //车架号
        carNo: '', //车牌号
        fixCenterName: '', //所属维修中心
        empName: '', //所属服务顾问
        workBillType: '', //工单类型
        subType: '', //工单分类
        customerName: '', //客户名称
        mobile1: '', //手机号1
        mobile12: '', //手机号2
        carMile: '', //车辆里程数
        dateIn: '', // 预约进场时间,
        advRepairItem: '', //建议维修项目
        advMaintenanceMiles: '', //建议下次保养里程
        advMaintenanceTime: '', //建议下次保养时间
        repairCus: '', //送修人
        repairCusphone: '', //送修人电话
        totalAmount: '', //合计金额
        receivableAmount: '', //应收款金额
        noPayments: '', //已收款金额
        kdtEntry: [
          // {
          //   entryId: "", //分录id
          //   repairItemNum: "", //工时
          //   repairItemName: "", //人工操作
          //   standardTime: "", //标准工时
          //   paice: "", //单价
          //   amout: "", //金额
          // },
        ],
        kdtMaterial: [
          // {
          //   entryId: "", //分录id
          //   materialNum: "", //配件编码
          //   materialName:"", //配件名称
          //   qty: "", //数量
          //   paice: "", //单价
          //   amout: "", //金额
          // },
        ],
        kdtVoucher: [
          // {
          //   entryId: "", //分录id
          //   voucherNum: "", //抵用卷卷号
          //   voucherId: "", //抵用卷名称
          //   qty: "", //数量
          //   paice: "", //单价
          //   amout: "", //金额
          //   time: "",
          // },
        ],
      },
      uploader: [],
      columns: [],
      showSelectPicker: false,
      detailId: '',
      tabActive: 0,
      userId: getCookies('userId'),
    }
  },

  mounted() {
    if (this.$route.query) {
      this.detailId = this.$route.query.billId
      this.getDetail(this.detailId)
    }
  },
  methods: {
    getDetail(billId) {
      repairApi
        .queryRepairWorkOrderById({
          billId,
          userId: this.userId,
        })
        .then((res) => {
          console.log(res)
          if (res.code == 1) {
            this.dataSource = res.data
          }
        })
    },
    handleApply() {
      Dialog.confirm({
        title: '提示',
        message: '是否结算？',
      }).then(() => {
        repairApi
          .repairWorkOrderSetOver({
            billId: 'ak5uxhDT+eFZ7nZVEUWM6LG53',
            userId: this.userId,
          })
          .then((res) => {
            console.log(res)
            if (res.success) {
              Notify({ type: 'success', message: '申请成功' })
              this.$router.go(-1)
            }
          })
          .catch(() => {
            // on cancel
          })
      })
    },
    onClickLeft() {
      this.$router.go(-1)
    },
  },
}
</script>

<style lang="less" scoped>
body {
  // background: #f3f3f3;
}

.flex {
  display: flex;
  align-items: center;
}

.registerDetail {
  background: #f3f3f3;

  .detail_header {
    justify-content: space-between;
    margin: 0.2rem 0.2rem;
    border-radius: 5px;
    background: #fff;
    padding: 0.3rem;

    .detail_header_lt {
      .carNo {
        font-size: 0.32rem;
        font-weight: bold;
        margin-bottom: 0.2rem;

        .icon-right {
          margin-left: 0.2rem;
          color: #409eff;
        }
      }

      .hank {
        font-size: 0.28rem;
        color: #666;
      }
    }

    .detail_header_rt {
      justify-content: flex-start;

      .txt {
        font-size: 0.28rem;
        color: #161616;
      }

      .icon-tel {
        color: #fff;
        background: #35bc04;
        font-size: 0.32rem;
        padding: 0.1rem;
        border-radius: 50%;
        margin-right: 0.1rem;
      }
    }
  }

  .formData {
    background: #fff;
  }
}

.label_item {
  color: #35bc04;
  border: 1px solid #35bc04;
  border-radius: 4px;
  margin-right: 0.1rem;
  padding: 0.01rem 0.2rem;
  font-size: 0.2rem;

  &:last-child {
    margin-right: 0;
  }
}

.tabBarBox {
  margin-top: 0.2rem;
}

.tabCar {
  margin-top: 0.1rem;
}

// 卡券
.cardList {
  margin: 0.1rem 0.2rem 0.3rem 0.2rem;
  box-sizing: border-box;
  overflow: hidden;

  .cardItem {
    background: #fff;
    border-radius: 10px;
    box-sizing: border-box;
    overflow: hidden;
    margin-bottom: 0.2rem;

    .box {
      overflow: hidden;

      .cardItem_lt {
        padding: 0.3rem 0.2rem;
        text-align: center;
        box-sizing: content-box;
        background: #ff91d7;
        color: #fff;
        overflow: hidden;
        height: 1.4rem;
        width: 30%;

        .price_icon {
          font-size: 0.3rem;
          color: #fff;
        }

        .price {
          color: #fff;

          .txt {
            font-size: 0.8rem;
            font-weight: bold;
          }

          .name {
            font-size: 0.28rem;
          }
        }
      }

      .cardItem_rt {
        padding: 0.3rem;
        border-bottom: 1px dashed #ccc;
        overflow: hidden;
        height: 1.4rem;
        width: 70%;

        .label_name {
          .label_txt {
            background: #ff3415;
            color: #fff;
            border-radius: 3px;
            text-align: center;
            padding: 0.07rem 0.2rem;
            font-size: 0.24rem;
            margin-right: 0.1rem;
          }

          .label_txt1 {
            margin-top: 0.4rem;
            color: #333;
            font-size: 0.28rem;
            font-weight: bold;
          }
        }

        .label_time {
          margin-top: 0.2rem;
          font-size: 0.26rem;
          color: #666;
        }
      }
    }

    .cardNo {
      padding: 0.2rem 0.3rem 0.2rem 0.2rem;
      font-size: 0.28rem;
      color: #333;
    }
  }
}

// 维修
.repairData {
  margin: 0.1rem 0.2rem 0.3rem 0.2rem;
  box-sizing: border-box;
  overflow: hidden;

  .repairItem {
    background: #fff;
    overflow: hidden;
    border-radius: 5px;
    padding: 0.2rem;
    margin-bottom: 0.2rem;

    .item_title {
      justify-content: space-between;
      padding: 0.1rem 0.1rem 0.2rem 0.3rem;
      border-bottom: 1px solid #f1f1f1;
      font-size: 0.28rem;
      margin-bottom: 0.3rem;
      position: relative;

      &::before {
        content: '';
        display: block;
        width: 3px;
        height: 15px;
        background: #409eff;
        position: absolute;
        left: 0;
        top: 5px;
      }
    }

    .item_content {
      padding: 0 0.3rem;

      .item_contentbox {
        justify-content: space-between;
      }

      .item_data {
        font-size: 0.28rem;
        margin-bottom: 0.2rem;
        display: flex;

        .item_data_label {
          color: #333;
        }

        .item_data_value {
          color: #262626;

          &.txt {
            line-height: 0.32rem;
          }
        }
      }

      .item_data_width {
        width: 4.5rem;
      }
    }
  }
}

// 联系人
.contactbox {
  margin: 0.1rem 0.2rem 0.3rem 0.2rem;

  .contactItem {
    justify-content: space-between;
    background: #fff;
    padding: 0.2rem;
    margin-bottom: 0.1rem;
    border-radius: 4px;

    .contact_lt {
      .header {
        margin-bottom: 0.2rem;
        color: #333;

        .txt {
          font-size: 0.2rem;
          margin-right: 0.2rem;
          background: #409eff;
          padding: 0.1rem 0.2rem;
          border-radius: 4px;
          color: #fff;
        }

        .name {
          font-size: 0.28rem;
        }
      }

      .tel {
        font-size: 0.3rem;
        color: #333;
      }
    }

    .contact_rt {
      .icon-wx {
        font-size: 0.7rem;
        color: #409eff;
      }

      .icon-tel {
        font-size: 0.36rem;
        background: #35bc04;
        color: #fff;
        text-align: center;
        padding: 0.1rem;
        border-radius: 50%;
        position: relative;
        top: -6px;
        margin-right: 0.1rem;
      }
    }
  }
}

.addBtn {
  position: fixed;
  bottom: 0.8rem;
  width: 100%;
  z-index: 1;

  .orderItem_filebox {
    width: 2.8rem;
    margin: auto;
    text-align: center;
    font-size: 0.28rem;
    background: #409eff;
    color: #fff;
    padding: 0.25rem 0rem;
    border-radius: 50px;
  }
}

.submitBtn {
  background: #409eff;
  color: #fff;
  width: 75%;
  margin: auto;
  text-align: center;
  padding: 0.25rem;
  border-radius: 5px;
  margin-top: 0.6rem;
  font-size: 0.3rem;
  margin-bottom: 0.4rem;
}

.doList {
  margin: 0.1rem 0.2rem 0.2rem 0.2rem;

  .doList_item {
    background: #fff;
    padding: 0.3rem;
    font-size: 0.26rem;
    color: #333;
    border-radius: 3px;
    margin-bottom: 0.2rem;

    .item_time {
      margin-bottom: 0.2rem;
    }

    .item_do {
      margin-bottom: 0.2rem;
      clear: both;

      .item_name {
        color: #646566;
        float: left;
        font-size: 0.28rem;
      }
    }

    .item_box {
      justify-content: space-between;

      .item_txt {
        font-size: 0.28rem;
        color: #646566;
      }
    }
  }
}

.noContent {
  margin-top: 0.2rem;
}
</style>
